package ai.service;

import org.eclipse.e4.core.di.annotations.Creatable;

import com.alibaba.dashscope.app.Application;
import com.alibaba.dashscope.app.ApplicationParam;
import com.alibaba.dashscope.app.ApplicationResult;

@Creatable
public class AIService {

	public synchronized String getAnswers(String questionContext) {

		ApplicationParam param = ApplicationParam.builder()
				.apiKey(System.getenv("apiKey")).appId(System.getenv("appId")).prompt(questionContext).build();

		Application application = new Application();
		ApplicationResult result;
		try {
			result = application.call(param);
			return result.getOutput().getText();
		} catch (Exception e) {
			e.printStackTrace();
			return e.getMessage();
		}

	}
}
